package com.sgcc.fj.pmos.e_fj_home.activity;

import android.annotation.SuppressLint;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.lifecycle.Lifecycle;

import com.alibaba.android.arouter.facade.annotation.Autowired;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.blankj.utilcode.util.GsonUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.sgcc.fj.pmos.arouter.home.HomeArouterPath;
import com.sgcc.fj.pmos.common.base.BaseActivity;
import com.sgcc.fj.pmos.common.base.IView;
import com.sgcc.fj.pmos.common.http.HttpInterConst;
import com.sgcc.fj.pmos.common.http.HttpRequestUtils;
import com.sgcc.fj.pmos.common.http.MvcNetCallback;
import com.sgcc.fj.pmos.common.http.MvpNetCallback;
import com.sgcc.fj.pmos.common.utils.AssetsUtil;
import com.sgcc.fj.pmos.common.utils.DialogUtil;
import com.sgcc.ln.pmos.common.widget.TitleBar;
import com.sgcc.pmos.nativesdk.R;
import com.sgcc.fj.pmos.e_fj_home.bean.CompanyInfoBean;
import com.sgcc.fj.pmos.e_fj_home.bean.MarketUserBean;
import com.sgcc.fj.pmos.e_fj_home.bean.MembersMarketBean;

import java.util.HashMap;
import java.util.Map;

import okhttp3.Call;

/**
 * 主体信息详情
 */
@Route(path = HomeArouterPath.HOME_MEMBERSMARKETINFO)
public class MembersMarketInfoActivity extends BaseActivity {

    private TitleBar mTitleBar;
    private TextView mTv1;
    private TextView mTv2;
    private TextView mTv3;
    private TextView mTv4;
    private TextView mTv5;
    private TextView mTv6;
    private TextView mTv7;
    private TextView mTv8;

    @Autowired
    public String membersId;

    @Override
    protected int getContentViewLayoutID() {
        return R.layout.activity_membersmarketinfo;
    }

    @Override
    protected void initViews() {
        super.initViews();
        findViewByIds();

        mTitleBar.setTitle("主体信息");
        mTitleBar.setRightIcon(R.mipmap.go_main, new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                goMainActivity();
            }
        });
        getData();
    }


    private void getData() {

        Map<String, Object> params = new HashMap<>();
        params.put("membersId", membersId);
        HttpRequestUtils.getInstance().request(params, HttpInterConst.QUERY_COMPANY_INFO_BY_ID,
                new MvcNetCallback<CompanyInfoBean>() {
                    @Override
                    public void onResponse(CompanyInfoBean response, int id) {
                        super.onResponse(response, id);
                        if (null != response && response.getStatus() == 0) {
                            if (null != response.getData()) {
                                CompanyInfoBean.Data bean = response.getData();


                                mTv1.setText(bean.getMembersName());
                                mTv2.setText(bean.getCreditcode());
                                mTv3.setText(bean.getLegalReprName());
                                mTv4.setText(bean.getEnterpriseType());
                                mTv5.setText(bean.getFounddate());
                                mTv6.setText(bean.getRegAddress());
                                mTv7.setText(bean.getTel());
                                mTv8.setText(bean.getScope());

                                if (!TextUtils.isEmpty(bean.getTel())) {
                                    mTv7.setOnClickListener(new View.OnClickListener() {
                                        @SuppressLint("MissingPermission")
                                        @Override
                                        public void onClick(View view) {
                                            try {
                                                DialogUtil.showCallPhone(mContext, bean.getTel());
                                            } catch (Exception e) {

                                            }
                                        }
                                    });
                                }


                            } else {
                                ToastUtils.showShort("未查询到该市场成员信息");
                            }
                        } else {
                            ToastUtils.showShort("未查询到该市场成员信息");
                        }


                    }
                });
    }

    private void findViewByIds() {
        mTitleBar = (TitleBar) findViewById(R.id.title_bar);
        mTv1 = (TextView) findViewById(R.id.tv_1);
        mTv2 = (TextView) findViewById(R.id.tv_2);
        mTv3 = (TextView) findViewById(R.id.tv_3);
        mTv4 = (TextView) findViewById(R.id.tv_4);
        mTv5 = (TextView) findViewById(R.id.tv_5);
        mTv6 = (TextView) findViewById(R.id.tv_6);
        mTv7 = (TextView) findViewById(R.id.tv_7);
        mTv8 = (TextView) findViewById(R.id.tv_8);
    }
}
